package samfeng.erp.product.dal.mysql;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Update;
import samfeng.erp.product.controller.admin.vo.ProductExportReqVO;
import samfeng.erp.product.controller.admin.vo.ProductPageReqVO;
import samfeng.erp.product.dal.dataobject.ProductDO;

/**
 * 商品 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface ProductMapper extends BaseMapperX<ProductDO> {

    default PageResult<ProductDO> selectPage(ProductPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ProductDO>()
                .betweenIfPresent(ProductDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(ProductDO::getSpuCode, reqVO.getSpuCode())
                .likeIfPresent(ProductDO::getName, reqVO.getName())
                .eqIfPresent(ProductDO::getSellPoint, reqVO.getSellPoint())
                .eqIfPresent(ProductDO::getDescription, reqVO.getDescription())
                .eqIfPresent(ProductDO::getLastCategoryId, reqVO.getLastCategoryId())
                .eqIfPresent(ProductDO::getAttributeId, reqVO.getAttributeId())
                .eqIfPresent(ProductDO::getSpecificationId, reqVO.getSpecificationId())
                .eqIfPresent(ProductDO::getPicUrls, reqVO.getPicUrls())
                .eqIfPresent(ProductDO::getStatus, reqVO.getStatus())
                .eqIfPresent(ProductDO::getSort, reqVO.getSort())
                .eqIfPresent(ProductDO::getSalesPrice, reqVO.getSalesPrice())
                .eqIfPresent(ProductDO::getMarketPrice, reqVO.getMarketPrice())
                .eqIfPresent(ProductDO::getCostPrice, reqVO.getCostPrice())
                .eqIfPresent(ProductDO::getStock, reqVO.getStock())
                .eqIfPresent(ProductDO::getSaleNum, reqVO.getSaleNum())
                .eqIfPresent(ProductDO::getPos, reqVO.getPos())
                .orderByDesc(ProductDO::getId));
    }

    default List<ProductDO> selectList(ProductExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ProductDO>()
                .betweenIfPresent(ProductDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(ProductDO::getSpuCode, reqVO.getSpuCode())
                .likeIfPresent(ProductDO::getName, reqVO.getName())
                .eqIfPresent(ProductDO::getSellPoint, reqVO.getSellPoint())
                .eqIfPresent(ProductDO::getDescription, reqVO.getDescription())
                .eqIfPresent(ProductDO::getLastCategoryId, reqVO.getLastCategoryId())
                .eqIfPresent(ProductDO::getAttributeId, reqVO.getAttributeId())
                .eqIfPresent(ProductDO::getSpecificationId, reqVO.getSpecificationId())
                .eqIfPresent(ProductDO::getPicUrls, reqVO.getPicUrls())
                .eqIfPresent(ProductDO::getStatus, reqVO.getStatus())
                .eqIfPresent(ProductDO::getSort, reqVO.getSort())
                .eqIfPresent(ProductDO::getSalesPrice, reqVO.getSalesPrice())
                .eqIfPresent(ProductDO::getMarketPrice, reqVO.getMarketPrice())
                .eqIfPresent(ProductDO::getCostPrice, reqVO.getCostPrice())
                .eqIfPresent(ProductDO::getStock, reqVO.getStock())
                .eqIfPresent(ProductDO::getSaleNum, reqVO.getSaleNum())
                .eqIfPresent(ProductDO::getPos, reqVO.getPos())
                .orderByDesc(ProductDO::getId));
    }

    @Update("update product_product set status = #{status} where id = #{id}")
    void updateStateById(@Param("status") String status,@Param("id") String id);

}
